package org.example.controller;

import org.example.domain.JsonData;
import org.example.domain.Meta;
import org.example.domain.MyLog;
import org.example.domain.PageBean;
import org.example.service.LogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * @author Jimmy
 * @version 1.0
 */
@Controller
@ResponseBody
public class LogController {

    @Autowired
    private LogService logService;

    /**
     * 分页查询（含条件）
     * @param pagenum 当前页数
     * @param pagesize 每页条目数
     * @return json
     */
    @GetMapping(value = "/logs")
    public JsonData<PageBean<MyLog>> pageBean(@RequestParam(required = false) String username, @RequestParam(required = false) String ip, @RequestParam(required = false) String time,int pagenum, int pagesize){
        Meta meta;
        PageBean<MyLog> pageBean = logService.findByPage(new MyLog(username,ip,time),pagenum, pagesize);
        if (pageBean != null){
            meta = new Meta("获取成功",200);
        }else {
            meta = new Meta("获取失败",404);
        }
        return new JsonData<>();
    }

}
